import pymysql
import random


def get_one():
   list = get_all()
   index = random.randint(0,len(list))
   return list[index]

def get_all():
   db = pymysql.connect(host='', user='',
                        password='', database='')
   cursor = db.cursor()
   # SQL 查询语句
   sql = "SELECT * FROM love_story"
   try:
      # 执行SQL语句
      cursor.execute(sql)
      # 获取所有记录列表
      results = cursor.fetchall()
      list = []
      for row in results:
         mesg = row[1]
         list.append(mesg)
      return list
   finally:
      # 关闭数据库连接
      db.close()
